package com.xxx.video.commen.utils;

import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import androidx.annotation.StringRes;

import com.xxx.video.VideoApplication;


public class T {
    public static boolean isShow = true;
    private static Toast mToast;

    /**
     * short visible Toast
     *
     * @param context context
     * @param message content
     */
    public static void showShort(Context context, CharSequence message) {
        if (isShow) {
            if (mToast == null) {
                mToast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
            } else {
                mToast.setText(message);
                mToast.setDuration(Toast.LENGTH_SHORT);
            }
            if (!TextUtils.isEmpty(message)) {
                mToast.show();
            }
        }

    }

    /**
     * short visible Toast
     *
     * @param context context
     * @param message content
     */
    public static void showShort(Context context, int message) {
        if (isShow) {
            if (mToast == null) {
                mToast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
            } else {
                mToast.setText(message);
                mToast.setDuration(Toast.LENGTH_SHORT);
            }
            mToast.show();
        }
    }

    /**
     * long visible Toast
     *
     * @param context context
     * @param message content
     */
    public static void showLong(Context context, CharSequence message) {
        if (isShow) {
            if (mToast == null) {
                mToast = Toast.makeText(context, message, Toast.LENGTH_LONG);
            } else {
                mToast.setText(message);
                mToast.setDuration(Toast.LENGTH_LONG);
            }
            mToast.show();
        }
    }

    /**
     * long visible Toast
     *
     * @param context context
     * @param message content
     */
    public static void showLong(Context context, int message) {
        if (isShow) {
            if (mToast == null) {
                mToast = Toast.makeText(context, message, Toast.LENGTH_LONG);
            } else {
                mToast.setText(message);
                mToast.setDuration(Toast.LENGTH_LONG);
            }
            mToast.show();
        }
    }

    /**
     * diy duration visible toast
     *
     * @param context  context
     * @param message  content
     * @param duration duration
     */
    public static void show(Context context, CharSequence message, int duration) {
        if (isShow) {
            if (mToast == null) {
                mToast = Toast.makeText(context, message, duration);
            } else {
                mToast.setText(message);
                mToast.setDuration(duration);
            }
            mToast.show();
        }
    }

    /**
     * diy duration visible toast
     *
     * @param context  context
     * @param message  content
     * @param duration duration
     */
    public static void show(Context context, int message, int duration) {
        if (isShow) {
            if (mToast == null) {
                mToast = Toast.makeText(context, message, duration);
            } else {
                mToast.setText(message);
                mToast.setDuration(duration);
            }
            mToast.show();
        }
    }

    /**
     * short visible toast
     *
     * @param message content
     */
    public static void show(String message) {
        if (isShow) {
            if (mToast == null) {
                mToast = Toast.makeText(VideoApplication.getInstance(), message, Toast.LENGTH_SHORT);
            } else {
                mToast.setText(message);
                mToast.setDuration(Toast.LENGTH_SHORT);
            }
            mToast.show();
        }
    }

    /**
     * long visible toast
     *
     * @param resId content
     */
    public static void show(@StringRes int resId) {
        if (isShow) {
            if (mToast == null) {
                mToast = Toast.makeText(VideoApplication.getInstance(), resId, Toast.LENGTH_SHORT);
            } else {
                mToast.setText(resId);
                mToast.setDuration(Toast.LENGTH_SHORT);
            }
            mToast.show();
        }
    }
}
